/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecom.entity;

import java.io.Serializable;
import java.util.List;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;


/**
 *
 * @author simon
 */
@Entity
public class Product implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    private Integer idProduct;
    private String name;
    private String description;
    private List<ProductStore> productStoreList;
    private Set<Image> imageList;
    private Category category;

    public Product() {
    }

    public Product(Integer idProduct) {
        this.idProduct = idProduct;
    }

    public Product(Integer idProduct, String name) {
        this.idProduct = idProduct;
        this.name = name;
    }

    public Integer getIdProduct() {
        return idProduct;
    }

    public void setIdProduct(Integer idProduct) {
        this.idProduct = idProduct;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<ProductStore> getProductStoreList() {
        return productStoreList;
    }

    public void setProductStoreList(List<ProductStore> productStoreList) {
        this.productStoreList = productStoreList;
    }

    public Set<Image> getImageList() {
        return imageList;
    }

    public void setImageList(Set<Image> imageList) {
        this.imageList = imageList;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idProduct != null ? idProduct.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.idProduct == null && other.idProduct != null) || (this.idProduct != null && !this.idProduct.equals(other.idProduct))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {

        String images = "";
        String stores = "";

        // Decompose les commandes dans une string
        if(imageList != null) {
            for (Image i : imageList) {
                images += " " + i.toString();
            }
        }
        // Decompose les adresses dans une string
        
        if(productStoreList != null) {
            for (ProductStore s : productStoreList) {
                stores += " " + s.getId().toString() + "; " + s.getPrice() + s.getStore().toString();
            }
        }

        /*return "ecom.dao.hbm.Product[idProduct=" + idProduct + ""
                + "\n name=" + name + ""
                + "\n description=" + description + ""
                + "\n imageList=" + images + ""
                + "\n category=" + category.toString() + ""
                + "\n productStoreList=" + stores + "]";*/
        
                String desc = "ID :" + idProduct + "\n";
                desc += "Nom :" + name + "\n";
                desc += "id Catégorie :"+category.getIdCategory()+",\tCatégorie :" + category.getLabel() + "\n";
                desc += "Magasins vendant le produit :\n";
                for (ProductStore productSt : productStoreList) {
                    desc += "\t\t" +"id Magasin :"+productSt.getStore().getIdStore()+",\t"+ productSt.getStore().getName() + " au prix de " + productSt.getPrice()+"\n\t\tStock :"+productSt.getStock() + "\n\n";
                }

                return desc;
    }

}
